﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PL_TileEditor
{
    public partial class EnemyViewer : ScrollableControl
    {
        public Bitmap EnemySheet = null;
        public Size EnemySize = new Size(128, 128);
        public int EnemyAI = 0;
        public int Frame = 0;
        public Rectangle CollisionRectangle = new Rectangle(32, 32, 64, 96);

        public EnemyViewer()
        {
            InitializeComponent();
            this.DoubleBuffered = true;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            if (EnemySheet != null)
            {
                e.Graphics.DrawImage(EnemySheet, new Rectangle(0, 0, EnemySize.Width, EnemySize.Height), new Rectangle(0, 0, EnemySize.Width, EnemySize.Height), GraphicsUnit.Pixel);
                e.Graphics.DrawImage(EnemySheet, new Rectangle(EnemySize.Width, 0, EnemySize.Width, EnemySize.Height), new Rectangle(EnemySize.Width * Frame + EnemySize.Width, 0, EnemySize.Width, EnemySize.Height), GraphicsUnit.Pixel);
                e.Graphics.DrawImage(EnemySheet, new Rectangle(0, EnemySize.Height, EnemySize.Width, EnemySize.Height), new Rectangle(0, EnemySize.Height, EnemySize.Width, EnemySize.Height), GraphicsUnit.Pixel);
                e.Graphics.DrawImage(EnemySheet, new Rectangle(EnemySize.Width, EnemySize.Height, EnemySize.Width, EnemySize.Height), new Rectangle(EnemySize.Width * Frame + EnemySize.Width, EnemySize.Height, EnemySize.Width, EnemySize.Height), GraphicsUnit.Pixel);

                Rectangle tempRect = CollisionRectangle;
                e.Graphics.DrawRectangle(new Pen(Color.FromArgb(255, 255, 255, 255)), tempRect);
                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(32, 0, 0, 0)), tempRect);
                tempRect.X += EnemySize.Width;
                e.Graphics.DrawRectangle(new Pen(Color.FromArgb(255, 255, 255, 255)), tempRect);
                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(32, 0, 0, 0)), tempRect);
                tempRect.X -= EnemySize.Width;
                tempRect.Y += EnemySize.Height;
                e.Graphics.DrawRectangle(new Pen(Color.FromArgb(255, 255, 255, 255)), tempRect);
                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(32, 0, 0, 0)), tempRect);
                tempRect.X += EnemySize.Width;
                e.Graphics.DrawRectangle(new Pen(Color.FromArgb(255, 255, 255, 255)), tempRect);
                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(32, 0, 0, 0)), tempRect);
            }
            else
            {
                e.Graphics.DrawString("Right click to set Enemy Image", new Font(FontFamily.GenericSansSerif, 16), Brushes.Black, 0, 0);
            }

            base.OnPaint(e);
        }
    }
}
